<?php
require_once "common.php";
require_once "db.php";
require_once "TopSdk.php";

define('TB_SHARE_URL', 'http://wow.taobao.com/view/item_share.htm?item_id=');

$error = 0;

$taobao_id = "12908245841";

$share = get_share($taobao_id);

function get_share($taobao_id='') {
    $share = NULL;
    if($taobao_id) {
        $url = TB_SHARE_URL.$taobao_id;
        $page = _curl_post($url);

        $n = preg_match("/href=\"http:\/\/item.taobao.com\/item.htm\?id=".$taobao_id."&tracelog=tfxskutitle\">(.*?)<\/a>/is", $page, $title);
        if($n) {
            $share = array();
            $share['title'] = trim($title[1]);
            $n = preg_match("/href=\"http:\/\/item.taobao.com\/item.htm\?id=".$taobao_id."&tracelog=tfxskupic\"><img src=\"([^\"]*)\"/is", $page, $img);
            if($n) $share['image'] = trim($img[1]);
            $n = preg_match_all("/all-share-brief.*?<img src=\"([^\"]*)\".*?<p class=\"person\-credit\">.*?href=\"([^\"]*)\".*?>(.*?)<\/a><\/p>.*?<s class=\"quote\"><\/s><a .*?>(.*?)<\/a><s class=\"close\-quote\"><\/s>.*?href=\"([^\"]*)\">查看详情<\/a>/is", $page, $shares);
            if($n && count($shares) == 6) {
                $share['brief'] = array();
                foreach($shares[1] as $k => $v) {
                    $share['brief'][] = array (
                        'avatar' => $v,
                        'user_space' => $shares[2][$k],
                        'user_nick' => $shares[3][$k],
                        'description' => $shares[4][$k],
                        'detail_url' => $shares[5][$k],
                    );
                }
            }
        }
    }
    return $share;
}
?>
